/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.open.api.core.service.processor.base.pre.callback;

import com.alibaba.fastjson2.JSON;
import info.peigen.hotpot.component.open.api.facade.order.OpenApiCallbackOrder;
import info.peigen.hotpot.component.open.api.facade.processor.base.OpenApiProcessor;
import info.peigen.hotpot.component.open.api.facade.processor.base.OpenApiProcessorServiceContext;
import info.peigen.hotpot.component.pay.wechat.facade.WechatPayCallbackService;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Inject;

/**
 * <b>(OpenApiCallbackBusinessTypeProcessor)</b>
 * <p>
 * 业务类型
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/9/20
 */
// @Component
@SuppressWarnings({"rawtypes", "SwitchStatementWithTooFewBranches", "unchecked"})
@Slf4j
public class OpenApiCallbackBusinessTypeProcessor implements OpenApiProcessor {

    @Inject
    WechatPayCallbackService wechatPayCallbackService;

    @Override
    public Integer level() {
        return 9;
    }

    @Override
    public void execute(OpenApiProcessorServiceContext serviceContext) {
        OpenApiCallbackOrder order        = (OpenApiCallbackOrder) serviceContext.getOrder();
        String               businessType = order.getBusinessType();
        String               data         = order.getData();
        log.info("准备处理回调：" + JSON.toJSONString(order));
        switch (businessType) {
            case "wechatPay":
                // todo peigen 修复支付回执
                // TradePayCallbackResult result = (TradePayCallbackResult) wechatPayCallbackService.paySuccessCallback(data);
                // serviceContext.setResult(BeanUtil.toBean(result, OpenSingleResult.class));
                break;
            default:
                break;
        }
    }
}